package com.food.controller;

import com.food.entity.pojo.OrderDetail;
import com.food.service.OrderDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/order-detail")
public class OrderDetailController {

    @Autowired
    private OrderDetailService orderDetailService;

    // 创建订单详情
    @PostMapping
    public void createOrderDetail(@RequestBody OrderDetail orderDetail) {
        orderDetailService.save(orderDetail);
    }

    // 获取所有订单详情
    @GetMapping
    public List<OrderDetail> getAllOrderDetails() {
        return orderDetailService.list();
    }

    // 根据ID获取订单详情
    @GetMapping("/{id}")
    public OrderDetail getOrderDetailById(@PathVariable Integer id) {
        return orderDetailService.getById(id);
    }

    // 更新订单详情
    @PutMapping
    public void updateOrderDetail(@RequestBody OrderDetail orderDetail) {
        orderDetailService.updateById(orderDetail);
    }

    // 删除订单详情
    @DeleteMapping("/{id}")
    public void deleteOrderDetail(@PathVariable Integer id) {
        orderDetailService.removeById(id);
    }
}
